package net.huashitong.Indicators.web;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.ObjectUtils;

import net.huashitong.Indicators.databean.IndicatorBreakdownDatabean;
import net.huashitong.Indicators.filter.IndicatorBreakdownFilter;
import net.huashitong.Indicators.service.IndicatorSecondService;
import net.huashitong.Indicators.utils.CodeUtils;
import net.huashitong.Indicators.utils.DataUtils;
import net.huashitong.Indicators.utils.DateForIndUtils;
import net.huashitong.Indicators.utils.IndustryNameUtils;
import net.huashitong.Indicators.utils.ThiTitleUtils;
@Controller
@RequestMapping("/app/indicatorSecond")
public class IndicatorSecondAppController extends JsonBaseController{
	
	@Autowired
	private IndicatorSecondService indicatorSecondService;
	@Override
	protected String getView(String arg0) {
		return null;
	}
	/**
	 * 指标二级所有数据
	 * @param filter
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping("/queryView")
	public Message  queryView(@RequestBody IndicatorBreakdownFilter filter)throws ParseException{
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();
		String date = DateForIndUtils.getMonth(filter.getDate());
		String cuDate = DateForIndUtils.getCMonth(filter.getDate());
		filter.setDate(date);
		filter.setCurrentMonth(cuDate);
		String judge = DataUtils.getValue(filter);
		filter=IndustryNameUtils.changeName(filter);
		//指标为月份的
		if("0".equals(judge)){
			//全市各县区排名情况
			 List<IndicatorBreakdownDatabean> databeans =indicatorSecondService.queryCountyRank(filter);
			 if(ObjectUtils.isNotBlank(databeans)){
			 map.put("type", "1");
			 map.put("data", databeans);
			 map.put("unit", "亿元");
			 map.put("title", "该指标全市排名一览");
			 map.put("descOne", date.substring(0, 4)+ThiTitleUtils.GXQZZL);
			 map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GXQJDZ);
			 map.put("secTitle", filter.getIndustryName()+"全市各县区排名情况");
			 maps.add(map);
			 }
		   // 当月同比增长情况
		    databeans =indicatorSecondService.queryMonthDevelopment(filter);
		   if(ObjectUtils.isNotBlank(databeans)){
			 map = new HashMap<String, Object>();
			 map.put("type", "2");
			 map.put("data", databeans);
			 map.put("monthOrQuarter", judge);
			 map.put("descOne", ThiTitleUtils.DYLJZZL);
			 map.put("descTwo", ThiTitleUtils.DYLJZZL);
			 map.put("title", "该指标发展情况");
			 map.put("secTitle", filter.getIndustryName()+"当月同比增长情况");
			 maps.add(map);
			}
		  /*//各月绝对值及同比增长情况
		   List<Map<String, Object>> list = indicatorSecondService.queryMonthAbsolute(filter);
		   if(ObjectUtils.isNotBlank(list)){
			map = new HashMap<String, Object>();
			map.put("descOne", date.substring(0, 4)+ThiTitleUtils.GYTBZZL);
			map.put("descTwo", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GYJDZ);
			map.put("descThi", date.substring(0, 4)+ThiTitleUtils.GYJDZ);
			map.put("type", "3");
			map.put("unit", "亿元");
			map.put("monthOrQuarter", CodeUtils.monthOrQuarter_mon);
			map.put("data", list);
			map.put("title", "该指标各月同比增长情况");
			map.put("secTitle",filter.getIndustryName()+ "各月"+ThiTitleUtils.JDZ+"和同比增长情况");
			maps.add(map);
		   }*/
			//累计比增同比增长情况
		     filter.setDate(date);
			filter.setCurrentMonth(cuDate);
			 List<Map<String, Object>> list = indicatorSecondService.queryLJAbsolute(filter);
			if(ObjectUtils.isNotBlank(list)){
					map = new HashMap<String, Object>();
					map.put("type", "4");
					map.put("descOne", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GYTBZZL);
					map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GYTBZZL);
					map.put("descThi", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GYLJJDZ);
					map.put("descFou", date.substring(0, 4)+ThiTitleUtils.GYLJJDZ);
					map.put("data", list);
					map.put("monthOrQuarter", CodeUtils.monthOrQuarter_mon);
					if("A19".equals(filter.getIndustryId())||"A18".equals(filter.getIndustryId())){
						map.put("unit", "收入/万元");
					}else{
						map.put("unit", "亿元");
					}
					map.put("title", "该指标累计同比增长情况");
					map.put("secTitle", filter.getIndustryName()+ "累计"+ThiTitleUtils.JDZ+"与同比增长情况");
					maps.add(map);
		    
		  }
		 //指标为季度的		
		  }else if("1".equals(judge)){
			 // GDP当季同比增长情况
			  filter.setDate(date);
			  filter.setCurrentMonth(cuDate);
			 List<IndicatorBreakdownDatabean> databeans =indicatorSecondService.queryDevelopmentSituation(filter);
			 if(ObjectUtils.isNotBlank(databeans)){
					map = new HashMap<String, Object>();
					map.put("type", "2");
					map.put("data", databeans);
					map.put("monthOrQuarter", CodeUtils.monthOrQuarter_qua);
					map.put("title", "该指标发展情况");
					map.put("descOne", ThiTitleUtils.DJTBZZL);
					map.put("descTwo", ThiTitleUtils.DJLJZZL);
					map.put("secTitle", filter.getIndustryName()+"当季同比增长情况");
					maps.add(map);
				}
			 
		  //累计同比增长情况
         List<Map<String, Object>>  list =indicatorSecondService.queryCumulativeGrowth(filter);
		 if(ObjectUtils.isNotBlank(list)){
					map = new HashMap<String, Object>();
					map.put("type", "4");
					map.put("data", list);
					map.put("descOne", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GJTBZZL);
					map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GJTBZZL);
					map.put("descThi", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GJLJJDZ);
					map.put("descFou", date.substring(0, 4)+ThiTitleUtils.GJLJJDZ);
					map.put("unit", "亿元");
					map.put("monthOrQuarter", CodeUtils.monthOrQuarter_qua);
					map.put("title", "该指标累计同比增长情况");
					map.put("secTitle", filter.getIndustryName()+"累计"+ThiTitleUtils.JDZ+"及同比增长情况");
					maps.add(map);
				}
		  }
		  map = new HashMap<String, Object>();
		  map.put("lists", maps);
		  map.put("monthOrQuarter", judge);
		  map.put("title", filter.getIndustryName()+"运行情况");
		 return coverMessage("200", "获取成功",map);
		
	}
}
